package com.bdzl.admin.controller.sys;

import java.util.List;
import java.util.Map;

import com.bdzl.pub.controller.BaseController;
import org.springframework.stereotype.Controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import com.bdzl.pub.entity.sys.MobileCodeDO;
import com.bdzl.admin.service.sys.MobileCodeService;
import com.bdzl.pub.util.param.PageUtils;
import com.bdzl.pub.util.param.Query;
import com.bdzl.pub.util.param.R;

/**
 * 手机验证码记录表
 * 
 * @author yangyicai
 * @email yangyicai@foxmail.com
 * @date 2021-03-23 13:59:22
 */
 
@Controller
@RequestMapping("/bdzl/mobileCode")
public class MobileCodeController extends BaseController {
	@Autowired
	private MobileCodeService mobileCodeService;
	
	@GetMapping()
	String MobileCode(){
	    return "bdzl/mobileCode/mobileCode";
	}
	
	@ResponseBody
	@GetMapping("/list")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		List<MobileCodeDO> mobileCodeList = mobileCodeService.list(query);
		int total = mobileCodeService.count(query);
		PageUtils pageUtils = new PageUtils(mobileCodeList, total);
		return pageUtils;
	}
	
	@GetMapping("/add")
	String add(){
	    return "bdzl/mobileCode/add";
	}

	/**
	 * @Author Zhn
	 * @Description //TODO 详情
	 * @Date 9:39 2021/5/24
	 * @Param [mobileCodeDO]
	 * @return com.bdzl.pub.entity.sys.MobileCodeDO
	 **/
	@PostMapping("/edit")
	@ResponseBody
	MobileCodeDO edit(@RequestBody MobileCodeDO mobileCodeDO){
		MobileCodeDO mobileCode = mobileCodeService.get(mobileCodeDO.getMcId());
	    return mobileCode;
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	public R save(@RequestBody MobileCodeDO mobileCode){
		if(mobileCodeService.save(mobileCode)>0){
			return R.ok();
		}
		return R.error();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	public R update( MobileCodeDO mobileCode){
		mobileCodeService.update(mobileCode);
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	public R remove( Integer mcId){
		if(mobileCodeService.remove(mcId)>0){
		return R.ok();
		}
		return R.error();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	public R remove(@RequestParam("ids[]") Integer[] mcIds){
		mobileCodeService.batchRemove(mcIds);
		return R.ok();
	}
	
}
